<?php

class UserWechatAction extends WechatAction {
	
	public function _initialize(){
		// $str=$_SERVER['PATH_INFO'];
		// $arr=explode("/", $str);
		// //获取最后一个/后边的字符
		// $_SESSION['url']=$arr[count($arr)-1].'?'.$_SERVER['QUERY_STRING'];
		
		// dump($_SESSION['url']);exit;
		// session(null); 
		// dump($_SERVER);exit;
		if(empty($_SESSION['url'])){
		$str=$_SERVER['PATH_INFO'];
		$arr=explode("/", $str);
		//获取最后一个/后边的字符
		$_SESSION['url']=$arr[count($arr)-1].'?'.$_SERVER['QUERY_STRING'];
		}
		// dump($_SESSION['url']);exit;
		$freeAuth = array('userlogin','tologin','wxinfo','get');
		if (!in_array(ACTION_NAME, $freeAuth)) {
			if(empty($_SESSION[user_info])){
		$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx23decee761dddfff&secret=2bd6289b4aaaef91aec2eaef7be93d6c";
		$token=$this->Get($url);
		$token=json_decode($token,true);	
		$url2="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23decee761dddfff&redirect_uri=http://www.nleaves.com/qinqin/wechat/user/wxinfo&response_type=code&scope=snsapi_base#wechat_redirect";
		// $token1=$this->Get($url2);
		// file_get_contents($url);
		// echo 111;exit;
		header('Location:'.$url2); 
		}

		}
		// session(null);  
		
		// echo $token1;exit;
	
				
	}

	public  function Get($url)
    	{
        if(function_exists('file_get_contents'))
        {
            $file_contents = file_get_contents($url);
        }
        else
        {
            $ch = curl_init();
            $timeout = 5;
            curl_setopt ($ch, CURLOPT_URL, $url);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            $file_contents = curl_exec($ch);
            curl_close($ch);
        }
        return $file_contents;
    }
	

}

?>